﻿using System;
using Database;
using System.Data;

namespace ObjectManager
{
    class DiemSinhVienDAO
    {
        private ConnectionDB cnn = null;

        public SinhVien SinhVien { get; set; }

        public DiemSinhVienDTO DiemSinhVienDTO { get; set; }

        public string TenLop { get; set; }

        public int MaLop { get; set; }

        public int MaMH { get; set; }

        private void Initialize()
        {
            cnn = Connection.Connect();
            SinhVien = new SinhVien();
            DiemSinhVienDTO = new DiemSinhVienDTO();
        }

        public DiemSinhVienDAO()
        {
            Initialize();
        }

        public DataTable Detail(TypeDiem type)
        {
            switch (type)
            {
                case TypeDiem.DiemSV:
                    return cnn.QueryProcedure("DiemSinhVien", SinhVien.ThongTin.Ma);
                case TypeDiem.DiemMH:
                    return cnn.QueryProcedure("DiemMonHoc_MaLop", MaMH, MaLop);
                default:
                    return null;
            }
        }

        public int Update()
        {
            return cnn.ExecuteProcedure("UpdateDiem", DiemSinhVienDTO.MaDK, DiemSinhVienDTO.DiemQT, DiemSinhVienDTO.DiemT);
        }

        public DataTable Diem()
        {
            //return cnn.Query("select DiemQT, DiemT, DiemTB, Loai from vw_ChiTietDiem where MaDK = {0};", DiemSinhVienDTO.MaDK);
            return cnn.Query("select * from vw_ChiTietDiem where MaDK = {0};", DiemSinhVienDTO.MaDK);
        }

        public DataTable ListNameS(int MaMonHoc, int MaLopDK)
        {
            return cnn.QueryProcedure("DanhSachDangKy_MaLop", MaMonHoc, MaLopDK);
        }
    }
}
